package com.hl.controller;

import com.github.pagehelper.PageHelper;
import com.hl.domain.User;
import com.hl.service.serviceImpl.UserServiceImpl;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/user")
@RestController

public class UserController {
@Autowired
    private UserServiceImpl userService;
//查全部
@GetMapping("/AllUserList")
  public R AllUserList(int pageNum,int pageSize ){
    PageHelper.startPage(pageNum,pageSize);
      List<User> userList = userService.AllUserList();
if (userList.size()>0){
    return R.success(userList);
}else {
    return R.fail("");
}


  }
  //新增用户
    @PostMapping("/insertUser")
  public  R insertSelective(User user){
    int i = userService.insertSelective(user);
    if (i==1){
        return R.success(user);
    }else {
        return R.fail("");
    }
  }
  //根据id删除
  @PostMapping("/deleteuserById")
    public R delectUserById(int id){
    int i = userService.delectUserById(id);
    if (i==1){
        return R.success("删除成功");
    }else {
        return R.fail("删除失败");
    }
  }
  //根据用户名模糊查询
  @GetMapping("/usernamelike")
  public R selectUsernameLike(String username){
    List<User> userList = userService.selectUserLike(username);
    if (userList.size()>0){
        return R.success(userList);
    }else {
        return R.fail("");
    }
  }
  //修改
    @PostMapping("/updateuser")
    public R  updateUser(User user){
    int i = userService.updateByPrimaryKeySelective(user);
    if (i==1){
        return R.success(user);
    }else {
        return R.fail("");
    }
    }
}
